#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QPixmap>
#include <QImage>
#include <QPicture>
paintDevice::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
//Pixmap绘图设备，专门为平台做显示优化
    // QPixmap pix(300,300);
    // //填充背景颜色
    // pix.fill(Qt::yellow);
    // QPainter painter(&pix);
    // painter.setPen(QPen(Qt::green));
    // painter.drawEllipse(QPoint(150,150),100,100);
    // //保存
    // pix.save("E:\\pix.png");
//QImage绘图设备，可以对像素进行访问
    // QImage img(300, 300, QImage::Format_RGB32);
    // img.fill(Qt::yellow);
    // QPainter painter(&img);
    // painter.setPen(QPen(Qt::green));
    // painter.drawEllipse(QPoint(150, 150), 100, 100);
    // img.save("E:\\img.png");
//QPicture可以记录和重现绘画指令
    QPicture pic;
    QPainter painter;
    painter.begin(&pic);//开始在pic上作画
    painter.setPen(QPen(Qt::cyan));
    painter.drawEllipse(QPoint(150, 150), 100, 100);
    painter.end();//结束作画
    pic.save("E:\\pic");
}

void paintDevice::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
// //利用QImage对图片像素进行修改
    // QImage img;
    // img.load(":/Image/1-6.png");
    // //修改像素点
    // for(int i=50;i<100;++i)
    // {
        // for(int j=50;j<100;++j)
        // {
            // QRgb val=qRgb(255,0,0);
            // img.setPixel(i,j,val);
        // }
    // }
    // painter.drawImage(0,0,img);
//重现picture
    QPicture pic;
    pic.load("E:\\pic");
    painter.drawPicture(0, 0, pic);
}
paintDevice::~Widget()
{
    delete ui;
}
